package com.uwantsoft.util.validator;


import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.math.BigDecimal;

/**
 * @author LeiPeichen.
 */
public class IsPositiveBigDecimalValidator implements ConstraintValidator<IsPositiveBigDecimal,String> {
    @Override
    public void initialize(IsPositiveBigDecimal constraintAnnotation) {

    }
    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        try{
            BigDecimal result = new BigDecimal(value);
            return result.compareTo(BigDecimal.ZERO) > 0 && result.scale() <= 2;
        }catch (Exception e){
            return false;
        }
    }
}
